﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using BLL;

public partial class problemsResult : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindProblem();
        }
    }

    void bindProblem()
    {
        if (Request["Id"] != null)
        {
            DAL.SecuritySubject subject = Security.getSubjectByID(Request["Id"]);
            lblsubject.Text = subject.Caption;
            dlproblems.DataSource = Security.getSecurityProblemList(Request["Id"]);
            dlproblems.DataBind();
        }
        else
        {
            Response.Write("<script>alert('没有权限！');history.back(0);</script>");
            return;
        }
    }
    DAL.SecurityEvaluateDataContext db = new SecurityEvaluateDataContext();
    protected void dlproblems_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string SoldierID = "";
            if (Request["SoldierID"] != null)
            {
                SoldierID = Request["SoldierID"];
            }
            else
            {
                Yipusoft.Account.Model.UserInfo user = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name);
                SoldierID = user.UserID;
            }
            Label ID = e.Item.FindControl("ID") as Label;
            ID.Text = e.Item.ItemIndex + 1 + "、";
            DAL.SecurityProblem problem = e.Item.DataItem as DAL.SecurityProblem;
            Label lblId = e.Item.FindControl("lblId") as Label;
            lblId.Text = problem.Id.ToString();
            Label lbltitle = e.Item.FindControl("lbltitle") as Label;
            lbltitle.Text = problem.Title;
            List<DAL.SecurityOption> options = (from aa in db.SecurityOption where aa.PId == problem.Id orderby aa.No select aa).ToList();
            if (problem.IsMultiple.Value == 1)
            {
                CheckBoxList cblselect = e.Item.FindControl("cblselect") as CheckBoxList;
                foreach (DAL.SecurityOption option in options)
                {
                    cblselect.Items.Add(new ListItem(option.No + "、" + option.OptionContent, option.Id.ToString()));
                }
            }
            else
            {
                RadioButtonList rblselect = e.Item.FindControl("rblselect") as RadioButtonList;
                foreach (DAL.SecurityOption option in options)
                {
                    rblselect.Items.Add(new ListItem(option.No + "、" + option.OptionContent, option.Id.ToString()));
                }
            }
            Label lblResult = e.Item.FindControl("lblResult") as Label;

            DAL.SecurityResult result = Security.getResult(User.Identity.Name, new Guid(Request["Id"].ToString()), problem.Id);
            if (result != null)
            {
                lblResult.Text = result.Result;
            }
            else
            {
                lblResult.Text = "";
            }
        }
    }
}
